#ifndef APPENDER_H
#define APPENDER_H

#include <iostream>

#include <QObject>
#include <QSharedPointer>
#include <QTextCodec>

#include "layout.h"

#define LOG_LEVEL_DEBUG 0
#define LOG_LEVEL_INFO  1
#define LOG_LEVEL_WARN  2
#define LOG_LEVEL_ERROR 3
#define LOG_LEVEL_FATAL 4

#define LOG_LEVEL_NAME_DEBUG "DEBUG"
#define LOG_LEVEL_NAME_INFO  "INFO"
#define LOG_LEVEL_NAME_WARN  "WARN"
#define LOG_LEVEL_NAME_ERROR "ERROR"
#define LOG_LEVEL_NAME_FATAL "FATAL"

namespace Log4Qt
{
    class Appender : public QObject
    {
        Q_OBJECT
    public:
        explicit Appender(const QString &name,
                          const QString &charset,
                          const QSharedPointer<Layout> &layout);

        virtual void append(const QString &loggerName,
                            const char *fileName,
                            int fileLine,
                            const QString &level,
                            const QString &msg) = 0;

    protected:
        QString name;
        QString charset;
        QSharedPointer<Layout> layout;
        QTextCodec *codec;

    private:
        static QSharedPointer<Appender> create(const QString &name);
    };

    class ConsoleAppender : public Appender
    {
    public:
        explicit ConsoleAppender(const QString &name,
                                 const QString &charset,
                                 const QSharedPointer<Layout> &layout);

        void append(const QString &loggerName,
                    const char *fileName,
                    int fileLine,
                    const QString &level,
                    const QString &msg) override;
    };
}
#endif // APPENDER_H
